<%@ page contentType="text/html;charset=UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %> 
<%@ taglib prefix="tags" tagdir="/WEB-INF/tags" %>
<c:set var="ctx" value="${pageContext.request.contextPath}"/>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
    
	
	<title>_登记取消订单</title>
	<script type="text/javascript">
	
	var curOrderno='';
	
	$(function() {
	    $("#_orderno").focus(); 
	    $("#_orderno").val(''); 
	    curOrderno='';
        $("#btn_cancel").hide();
        $("[name='exist']").hide();
        $("[name='noexist']").show();
        $("#msg").html("");
    });
	
	function cancelOrder(){
	    $.ajax({
 			type:'post',
 			url:'${ctx}/cancelOrder/ajaxCancelOrder',
 			data:{
 				orderno:curOrderno
 			},
 			dataType:'json',
 			success:function(data) {
 				var msg=data.msg;
 				
 			    if(msg=='success'){ //取消成功
 				     $("#msg").css("color","green");
				     $("#msg").html("取消成功。");
				     $("#btn_cancel").hide();
				     curOrderno='';
 				}else{
 				     alert("网络繁忙，请稍后重试...");
 				}
 				
 				$("#_orderno").val('');
			    $("#_orderno").focus();
			    $("[name='exist']").hide();
			    $("[name='noexist']").show();
 				
 			},
 			error:function() {
 				alert("网络繁忙，请稍后重试...");
 			}
 	   });
	}
	
	function query(){
        var orderno=$("#_orderno").val().trim();
        curOrderno='';
        $("#btn_cancel").hide();
        $("[name='exist']").hide();
        $("[name='noexist']").show();
        $("#msg").html("");
         
        
        if(orderno==''){
           $("#msg").css("color","red");
		   $("#msg").html("请输入订单编号！");
		   $("#_orderno").focus(); 
		   $("#_orderno").val(''); 
		   curOrderno='';
		   return false;
        }
         
        
        $.ajax({
 			type:'post',
 			url:'${ctx}/cancelOrder/ajaxQueryCancelOrder',
 			data:{
 				orderno:orderno
 			},
 			dataType:'json',
 			success:function(data) {
 			
 				var msg=data.msg;
 				var flag=data.flag;
 				var ediOrder=data.ediOrder;
 				var workOrder=data.workOrder;
 				
 				if(msg == 'qmNotCreate'){
 				   $("#msg").css("color","red");
				   $("#msg").html("奇门商家不允许手工创建取消单！");
				   
				   showOrderInfo(ediOrder,workOrder);
 				   
 				   $("#_orderno").val('');
				   $("#_orderno").focus();
 				}else if(msg=='noExist'){
 				
 				   $("#msg").css("color","red");
				   $("#msg").html("不存在此运单号！");
				   
 				   $("#_orderno").val('');
				   $("#_orderno").focus();
				   $("[name='exist']").hide();
				   $("[name='noexist']").show();
				   
 				}
 				else if(msg=='cancel'){
 				   $("#msg").css("color","red");
				   $("#msg").html("此单已经取消，不能重复登记！");
 				   showOrderInfo(ediOrder,workOrder);
 				   
 				   $("#_orderno").val('');
				   $("#_orderno").focus();
 				}
 				else if(msg=='recall'){
 				   $("#msg").css("color","red");
				   $("#msg").html("此单已经取消重发，不能取消原单，可以继续取消重发单！");
 				   showOrderInfo(ediOrder,workOrder);
 				   
 				   $("#_orderno").val('');
				   $("#_orderno").focus();
 				}
 				else if(msg=='sended'){
 				   $("#msg").css("color","red");
				   $("#msg").html("此单已经发货，不能登记取消！");
 				   showOrderInfo(ediOrder,workOrder);
 				   
 				   $("#_orderno").val('');
				   $("#_orderno").focus();
 				}
 				else if(ediOrder.customerCode=='MID'){
 				   $("#msg").css("color","red");
				   $("#msg").html("美的的订单不允许登记异常单，请联系美的驻仓人员");
 				   showOrderInfo(ediOrder,workOrder);
 				   
 				   $("#_orderno").val('');
				   $("#_orderno").focus();
 				}
 				else{
 				   $("#btn_cancel").show();
 				   showOrderInfo(ediOrder,workOrder);
 				   curOrderno=orderno;
 				}
 				
 				 if(flag=="true"){
 				      $("#expressNo").html(workOrder.expressNo);
		 			  var status=workOrder.status;
		 			  
				      if(status=='1'){ 
				    	   $("#status").html("创建批次");
				      }else if(status=='2'){
				    	   $("#status").html("创建任务");
				      }else if(status=='3'){
				    	   $("#status").html("已拣货");
				      }else if(status=='4'){
				    	   $("#status").html("已灯光拣选");
				      }else if(status=='5'){
				    	   $("#status").html("已包装");
				      }else if(status=='6'){
				    	   $("#status").html("已发货");
				      }else if(status=='7'){
				    	   $("#status").html("已签收");
				      }else if(status=='8'){
				    	   $("#status").html("异常");
				      }else if(status=='9'){
				    	   $("#status").html("待包装");
				      }
 				   }else if(flag=='false'){
 				      $("#status").html("未进入作业批次");
 				   }
 				   
 				
 			},
 			error:function() {
 				alert("网络繁忙，请稍后重试...");
 			}
 	   });
     }
     
     function showOrderInfo(order,workOrder){
	       $("[name='exist']").show();
	       $("[name='noexist']").hide();
	       
	       
	       if(workOrder != null){
	          $("#express").html(workOrder.expressNo+workOrder.ebillNo);
	       }
	       
	       if(order!= null){
	           $("#orderno").html(order.ordeno);
		       $("#expressName").html(order.cacode);
		       $("#address").html(order.addres);
		       $("#postco").html(order.postco);
		       $("#custna").html(order.custna);
		       $("#mobile").html(order.mobile);
		       $("#teleph").html(order.teleph);
		       
		       var orderType=order.orderType;
		       if(orderType=='single'){ 
		    	   $("#orderType").html("单件");
		       }else if(orderType=='multiple'){
		    	   $("#orderType").html("多件");
		       }
	       }
	       
	 }
	   
    </script>
</head>

<body>
<section class="content">
	<div class="row">
		<div class="col-md-12">
			<!-- Primary box -->
			<div class="box box-solid box-primary">
				<div class="box-header">
					<i class="fa fa-list"></i>
					<h3 class="box-title">登记取消单</h3>
					<div class="box-tools pull-right">
						<button class="btn btn-primary btn-sm" data-widget="collapse">
							<i class="fa fa-minus"></i>
						</button>
					</div>
				</div>
				<div class="box-body">		
	<table class="table table-striped table-bordered table-condensed" style="margin-top: 0px;">
		<tr><td>
			<span class="form-search">
			    <label style="margin-left: 10px;" >订单编号:</label>
				<input  type="text" id="_orderno" name="_orderno" onchange="query();"/>
				<span style="margin-left:12px; margin-top: 10px; color: red;font-weight: bold;" id="msg"></span>
		    </span>
	    </td></tr>
	</table>
	</div>
	</div>
	</div>
	</div>
	
	
	<div class="row">
		<div class="col-md-12">
			<!-- Primary box -->
			<div class="box box-solid box-primary">
				<div class="box-header">
					<i class="fa fa-list"></i>
					<h3 class="box-title">订单信息</h3>
					<div class="box-tools pull-right">
						<button class="btn btn-primary btn-sm" data-widget="collapse">
							<i class="fa fa-minus"></i>
						</button>
					</div>
				</div>
				<div class="box-body">	
	<!-- 订单信息 -->
	<table class="table table-striped table-bordered table-condensed" style="margin-top: 0px;">
		<tr name="noexist">
		     <td colspan="9" height="50"  style="vertical-align:middle; text-align: center;color: gray;font-size: 20px;">无数据</td>
		</tr>
		
		<thead name="exist" style="display: none;">
		    <th>订单编号</th>
			<th>运单编号</th>
			<th>快递公司</th>
			<th>收货人</th>
			<th>联系手机</th>
			<th>联系座机</th>
			<th>收货人地址</th>
			<th>订单状态</th>
		</thead>
		
		<tr name="exist" style="display: none;">
		    <td id="orderno"></td>
		    <td id="express"></td>
		    <td id="expressName"></td>
		    <td id="custna"></td>
		    <td id="mobile"></td>
		    <td id="teleph"></td>
		    <td id="address"></td>
		    <td id="status"></td>
		  </tr>
	</table>
	</div>
	</div>
	</div>
	</div>
	
	<div class="modal-footer bg-gray">
		<button type="button" class="btn btn-primary" id="btn_cancel" style="margin-left: 10px;display: none;" onclick="cancelOrder();" >登记取消</button>
		<a href="${ctx}/v2/backOrder/show" role="button"  class="btn btn-info" >返回</a>
	</div>
	</section>
	
</body>
</html>
